package cn.aitrox.ry.service.anno.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.anno.dao.AnnoComponentResultDao;
import cn.aitrox.ry.service.anno.entity.AnnoComponentResultEntity;
import cn.aitrox.ry.service.anno.mapper.AnnoComponentResultMapper;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class AnnoComponentResultDaoImpl extends BaseDaoImpl<AnnoComponentResultEntity> implements AnnoComponentResultDao {

    @Autowired
    private AnnoComponentResultMapper mapper;

    @Override
    public void batchSave(List<AnnoComponentResultEntity> list) {
        super.batchInsert(list, 1000, new MapperSqlCallback<AnnoComponentResultEntity>() {
            @Override
            public void batchInsert(List<AnnoComponentResultEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public List<AnnoComponentResultEntity> findByArIdAlrId(Integer arId, Integer alrId) {
        if (null == arId && null == alrId) {
            return new ArrayList<>();
        }
        AnnoComponentResultEntity cond = new AnnoComponentResultEntity();
        cond.setArId(arId);
        cond.setAlrId(alrId);
        return super.findByCondition(cond, null);
    }

    @Override
    public List<AnnoComponentResultEntity> findByArIds(List<Integer> arIdList) {
        return mapper.findByArIds(arIdList);
    }

    @Override
    public void deleteByAlrIds(List<Integer> alrIds) {
        if (ArrayUtil.isEmpty(alrIds)) {
            return;
        }
        mapper.deleteByAlrIds(alrIds);
    }
}
